package com.glg.messagewall;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageController {
    private List<MessageInfo> messageInfos = new ArrayList<>();

    /**
     * 1. 发布留言
     * @param messageInfo
     * @return
     */
    @RequestMapping("/publish")
    public Boolean publish(MessageInfo messageInfo) {
        System.out.println("接收参数，messageInfo："+messageInfo);

        //1. 参数校验
        if(!StringUtils.hasLength(messageInfo.getFrom())
                || !StringUtils.hasLength(messageInfo.getTo())
                || !StringUtils.hasLength(messageInfo.getSay())) {
            return false;
        }
        //2. 存储数据（暂时存在内存中）
        messageInfos.add(messageInfo);
        return true;
    }


    /**
     * 2. 获取留言信息
     * @return
     */
    @RequestMapping("/getList")
    private List<MessageInfo> getList() {
        return messageInfos;
    }
}
